from wtforms.form import Form
from app.libs.error_code import ParameterException
from flask.globals import request

class MyBaseForm(Form):
    
    #def __init__(self, data):
    def __init__(self):
        #调用父类BaseForm的__init__
        data = request.json
        #super(current_class, self).current_method()
        super(MyBaseForm, self).__init__(data=data)
        
    def validate_for_api(self):
        #调用父类BaseForm的validate方法
        valid = super(MyBaseForm, self).validate()
        if not valid:  #valid为空时(即表单数据有误时)
            raise ParameterException
        return self